18. Choosing good data structures
Choosing Good Data Structures
Lists
Lists are good when:
- Your data is ordered (and indexing based on position-in-list makes sense).
- You need to keep track of duplicates.
- Your data is mutable (dictionary keys and elements in a set must be immutable).
Sets
Sets are good for:
- Fast membership testing.
- Removing duplicates from a sequence.
- Computing mathematical operations like intersection, union, and difference.
Dictionaries
Dictionaries are good when:
- You want to associate keys with values.
- You want fast key-based lookups.